<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>翻卡抽奖 - 课翼管家</title>
    <link rel="stylesheet" href="css/font-awesome.all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            overflow-x: hidden;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            text-align: center;
            color: white;
            margin-bottom: 30px;
        }

        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        }

        .header p {
            font-size: 1.2rem;
            opacity: 0.9;
        }

        /* 输入区域样式和隐藏动画 */
        .input-section {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 30px;
            margin-bottom: 30px;
            box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
            border: 1px solid rgba(255, 255, 255, 0.18);
            transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
            overflow: hidden;
        }

        .input-section.hidden {
            opacity: 0;
            transform: translateY(-30px) scale(0.95);
            max-height: 0;
            padding: 0;
            margin: 0;
            border: none;
        }

        .input-group {
            display: flex;
            gap: 15px;
            margin-bottom: 20px;
            flex-wrap: wrap;
        }

        .input-group textarea {
            flex: 1;
            min-width: 300px;
            padding: 15px;
            border: none;
            border-radius: 15px;
            font-size: 16px;
            background: rgba(255, 255, 255, 0.9);
            resize: vertical;
            min-height: 100px;
        }

        .btn {
            padding: 12px 30px;
            border: none;
            border-radius: 25px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        }

        .btn-primary {
            background: linear-gradient(45deg, #ff6b6b, #ffa500);
            color: white;
        }

        .btn-secondary {
            background: linear-gradient(45deg, #4ecdc4, #44a08d);
            color: white;
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
        }

        /* 神秘礼盒卡片样式 */
        .cards-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 30px;
            margin-top: 40px;
            perspective: 1000px;
            transition: all 0.5s ease;
        }

        .mystery-card {
            width: 200px;
            height: 250px;
            position: relative;
            cursor: pointer;
            transform-style: preserve-3d;
            transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
            margin: 0 auto;
        }

        .mystery-card:hover:not(.flipped) {
            transform: translateY(-5px) scale(1.05);
        }

        .mystery-card.flipped {
            transform: rotateY(180deg);
        }

        .card-face {
            position: absolute;
            width: 100%;
            height: 100%;
            backface-visibility: hidden;
            border-radius: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
            border: 2px solid rgba(255, 215, 0, 0.5);
        }

        .card-front {
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
            color: white;
            position: relative;
            overflow: hidden;
        }

        .card-front::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: linear-gradient(45deg, transparent, rgba(255, 215, 0, 0.1), transparent);
            transform: rotate(45deg);
            animation: shimmer 3s infinite;
        }

        @keyframes shimmer {
            0% {
                transform: translateX(-100%) translateY(-100%) rotate(45deg);
            }

            100% {
                transform: translateX(100%) translateY(100%) rotate(45deg);
            }
        }

        .mystery-icon {
            font-size: 60px;
            margin-bottom: 15px;
            animation: float 3s ease-in-out infinite;
            filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.5));
        }

        @keyframes float {

            0%,
            100% {
                transform: translateY(0px);
            }

            50% {
                transform: translateY(-10px);
            }
        }

        .card-back {
            background: linear-gradient(135deg, #ff6b6b 0%, #ffa500 100%);
            color: white;
            transform: rotateY(180deg);
            padding: 30px;
            text-align: center;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            top: 0px
        }

        .prize-title {
            font-size: 28px;
            font-weight: bold;
            margin-bottom: 15px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        }

        .prize-description {
            font-size: 18px;
            opacity: 0.9;
            line-height: 1.4;
        }

        /* 全屏模态框样式 */
        .fullscreen-modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.8);
            backdrop-filter: blur(10px);
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 10000;
            animation: fadeIn 0.3s ease;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
            }

            to {
                opacity: 1;
            }
        }

        .fullscreen-prize {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 30px;
            padding: 60px;
            text-align: center;
            color: white;
            max-width: 80%;
            max-height: 80%;
            animation: zoomIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
            border: 3px solid gold;
        }

        @keyframes zoomIn {
            from {
                transform: scale(0.5) rotate(10deg);
                opacity: 0;
            }

            to {
                transform: scale(1) rotate(0deg);
                opacity: 1;
            }
        }

        .fullscreen-icon {
            font-size: 120px;
            margin-bottom: 30px;
            animation: bounce 1s ease-in-out infinite;
            filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.7));
        }

        @keyframes bounce {

            0%,
            100% {
                transform: translateY(0);
            }

            50% {
                transform: translateY(-20px);
            }
        }

        .fullscreen-title {
            font-size: 48px;
            font-weight: bold;
            margin-bottom: 20px;
            text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
        }

        .fullscreen-description {
            font-size: 24px;
            opacity: 0.9;
            line-height: 1.5;
        }

        .close-fullscreen {
            position: absolute;
            top: 20px;
            right: 20px;
            background: rgba(255, 255, 255, 0.2);
            border: none;
            color: white;
            font-size: 30px;
            cursor: pointer;
            width: 60px;
            height: 60px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
        }

        .close-fullscreen:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: scale(1.1);
        }

        /* 卡片入场动画 */
        @keyframes cardEntrance {
            from {
                opacity: 0;
                transform: scale(0.8) translateY(20px);
            }

            to {
                opacity: 1;
                transform: scale(1) translateY(0);
            }
        }

        .mystery-card {
            animation: cardEntrance 0.6s ease-out backwards;
        }

        /* 魔法粒子效果 */
        .particle {
            position: absolute;
            width: 4px;
            height: 4px;
            background: gold;
            border-radius: 50%;
            pointer-events: none;
            animation: particle-float 2s ease-in-out infinite;
        }

        @keyframes particle-float {

            0%,
            100% {
                transform: translateY(0) scale(0);
                opacity: 0;
            }

            50% {
                transform: translateY(-50px) scale(1);
                opacity: 1;
            }
        }

        /* 重新开始按钮样式 */
        .restart-btn {
            position: fixed;
            bottom: 30px;
            right: 30px;
            background: linear-gradient(45deg, #ff6b6b, #ffa500);
            color: white;
            padding: 15px 30px;
            border: none;
            border-radius: 50px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
            transition: all 0.3s ease;
            z-index: 1000;
            display: none;
        }

        .restart-btn:hover {
            transform: translateY(-3px) scale(1.05);
            box-shadow: 0 12px 35px rgba(0, 0, 0, 0.4);
        }

        .restart-btn.show {
            display: block;
            animation: bounceIn 0.6s ease;
        }

        @keyframes bounceIn {
            0% {
                opacity: 0;
                transform: scale(0.3) translateY(100px);
            }

            50% {
                transform: scale(1.05) translateY(-10px);
            }

            100% {
                opacity: 1;
                transform: scale(1) translateY(0);
            }
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .cards-container {
                grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
                gap: 20px;
            }

            .mystery-card {
                width: 150px;
                height: 200px;
            }

            .fullscreen-prize {
                padding: 40px 20px;
                max-width: 95%;
            }

            .fullscreen-icon {
                font-size: 80px;
            }

            .fullscreen-title {
                font-size: 32px;
            }

            .fullscreen-description {
                font-size: 18px;
            }

            .restart-btn {
                bottom: 20px;
                right: 20px;
                padding: 12px 25px;
                font-size: 14px;
            }
        }

        /* 音乐控制样式 */
        .music-control {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1000;
        }

        .music-btn {
            background: rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(10px);
            border: none;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            color: white;
            font-size: 20px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .music-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: scale(1.1);
        }

        .back-btn {
            position: fixed;
            top: 20px;
            left: 20px;
            background: rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(10px);
            color: white;
            padding: 10px 20px;
            border-radius: 25px;
            text-decoration: none;
            transition: all 0.3s ease;
            z-index: 1000;
        }

        .back-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: translateX(-5px);
        }
    </style>
</head>

<body>
    <a href="星星.html" class="back-btn">
        <i class="fas fa-arrow-left"></i> 返回主页
    </a>

    <div class="music-control">
        <button class="music-btn" id="musicToggle">
            <i class="fas fa-volume-up"></i>
        </button>
    </div>

    <!-- 重新开始按钮 -->
    <button class="restart-btn" id="restartBtn" onclick="resetLottery()">
        <i class="fas fa-redo"></i> 重新开始
    </button>

    <!-- 全屏模态框 -->
    <div class="fullscreen-modal" id="fullscreenModal">
        <div class="fullscreen-prize">
            <div class="fullscreen-icon" id="fullscreenIcon">🎁</div>
            <h2 class="fullscreen-title" id="fullscreenTitle">奖品名称</h2>
            <p class="fullscreen-description" id="fullscreenDescription">奖品描述</p>
        </div>
        <button class="close-fullscreen" onclick="closeFullscreen()">
            <i class="fas fa-times"></i>
        </button>
    </div>

    <div class="container">
        <div class="header">
            <h1><i class="fas fa-mystery-gift"></i> 神秘翻卡抽奖</h1>
            <p>设置神秘奖品，点击礼盒揭晓惊喜！</p>
        </div>

        <div class="input-section" id="inputSection">
            <h2 style="color: white; margin-bottom: 15px; font-size: 1.5rem;">
                <i class="fas fa-crown"></i> 设置神秘奖品
            </h2>
            <p style="color: rgba(255,255,255,0.8); margin-bottom: 15px;">
                请输入神秘奖品种类，每行一个奖品（例如：精品铅笔、精美贴画、零食、精美礼品、安慰奖等）
            </p>
            <div class="input-group">
                <textarea id="prizeInput" placeholder="精品铅笔📝&#10;精美贴画🎨&#10;美味零食🍪&#10;神秘大礼包🎁&#10;幸运安慰奖✨"></textarea>
            </div>
            <div class="input-group">
                <button class="btn btn-primary" onclick="generateMysteryCards()">
                    <i class="fas fa-magic"></i> 生成神秘礼盒
                </button>
                <button class="btn btn-secondary" onclick="resetLottery()">
                    <i class="fas fa-redo"></i> 重新开始
                </button>
            </div>
        </div>

        <div class="cards-container" id="cardsContainer"></div>
    </div>

    <audio id="backgroundMusic" loop>
        <source src="mp3/suiji.m4a" type="audio/mpeg">
    </audio>

    <script>
        let cards = [];
        let isMusicPlaying = false;
        const music = document.getElementById('backgroundMusic');
        const musicToggle = document.getElementById('musicToggle');
        const restartBtn = document.getElementById('restartBtn');

        // 背景音乐控制
        musicToggle.addEventListener('click', function () {
            if (isMusicPlaying) {
                music.pause();
                musicToggle.innerHTML = '<i class="fas fa-volume-mute"></i>';
            } else {
                music.play().catch(e => console.log('音乐播放失败:', e));
                musicToggle.innerHTML = '<i class="fas fa-volume-up"></i>';
            }
            isMusicPlaying = !isMusicPlaying;
        });

        // 打乱数组
        function shuffleArray(array) {
            const newArray = [...array];
            for (let i = newArray.length - 1; i > 0; i--) {
                const j = Math.floor(Math.random() * (i + 1));
                [newArray[i], newArray[j]] = [newArray[j], newArray[i]];
            }
            return newArray;
        }

        // 隐藏输入区域
        function hideInputSection() {
            const inputSection = document.getElementById('inputSection');
            inputSection.classList.add('hidden');
        }

        // 显示输入区域
        function showInputSection() {
            const inputSection = document.getElementById('inputSection');
            inputSection.classList.remove('hidden');
        }

        // 显示重新开始按钮
        function showRestartButton() {
            restartBtn.classList.add('show');
        }

        // 隐藏重新开始按钮
        function hideRestartButton() {
            restartBtn.classList.remove('show');
        }

        // 生成神秘礼盒
        function generateMysteryCards() {
            const prizeInput = document.getElementById('prizeInput').value.trim();
            if (!prizeInput) {
                alert('请输入神秘奖品信息！');
                return;
            }

            const prizes = prizeInput.split('\n').filter(p => p.trim());
            if (prizes.length === 0) {
                alert('请输入有效的奖品信息！');
                return;
            }

            // 隐藏输入区域
            hideInputSection();

            const shuffledPrizes = shuffleArray(prizes);
            const container = document.getElementById('cardsContainer');
            container.innerHTML = '';

            // 奖品图标映射
            const prizeIcons = {
                '铅笔': '📝', '笔': '✏️', '贴画': '🎨', '零食': '🍪', '糖': '🍬',
                '礼品': '🎁', '礼包': '🎁', '玩具': '🧸', '书': '📚', '本': '📒',
                '奖': '🏆', '星': '⭐', '心': '❤️', '花': '🌸', '彩': '🌈'
            };

            shuffledPrizes.forEach((prize, index) => {
                const card = document.createElement('div');
                card.className = 'mystery-card';
                card.style.animationDelay = `${index * 0.1}s`;

                let icon = '🎁';
                let title = prize;
                let description = '神秘奖品等你揭晓！';

                // 智能匹配图标
                for (const [key, emoji] of Object.entries(prizeIcons)) {
                    if (prize.includes(key)) {
                        icon = emoji;
                        break;
                    }
                }

                // 解析奖品格式
                if (prize.includes('：')) {
                    [title, description] = prize.split('：');
                }

                card.innerHTML = `
                    <div class="card-face card-front">
                        <div class="mystery-icon">🎁</div>
                        <div style="font-size: 16px; opacity: 0.9;">神秘礼盒</div>
                        <div style="font-size: 12px; opacity: 0.7; margin-top: 5px;">点击揭晓</div>
                    </div>
                    <div class="card-face card-back">
                        <div class="mystery-icon">${icon}</div>
                        <h3 class="prize-title">${title}</h3>
                        <p class="prize-description">${description}</p>
                    </div>
                `;

                card.addEventListener('click', function () {
                    if (!this.classList.contains('flipped')) {
                        this.classList.add('flipped');

                        // 播放音效
                        if (isMusicPlaying) {
                            const flipSound = new Audio('mp3/success.wav');
                            flipSound.play().catch(e => console.log('音效播放失败:', e));
                        }

                        // 延迟显示全屏
                        setTimeout(() => {
                            showFullscreen(icon, title, description);
                        }, 600);
                    }
                });

                container.appendChild(card);
            });

            // 显示重新开始按钮
            setTimeout(() => {
                showRestartButton();
            }, 1000);
        }

        // 显示全屏奖品
        function showFullscreen(icon, title, description) {
            const modal = document.getElementById('fullscreenModal');
            document.getElementById('fullscreenIcon').textContent = icon;
            document.getElementById('fullscreenTitle').textContent = title;
            document.getElementById('fullscreenDescription').textContent = description;

            modal.style.display = 'flex';

            // 添加魔法粒子效果
            createParticles();
        }

        // 关闭全屏
        function closeFullscreen() {
            const modal = document.getElementById('fullscreenModal');
            modal.style.display = 'none';
        }

        // 创建魔法粒子
        function createParticles() {
            const container = document.querySelector('.fullscreen-prize');
            for (let i = 0; i < 20; i++) {
                const particle = document.createElement('div');
                particle.className = 'particle';
                particle.style.left = Math.random() * 100 + '%';
                particle.style.animationDelay = Math.random() * 2 + 's';
                container.appendChild(particle);

                setTimeout(() => {
                    particle.remove();
                }, 2000);
            }
        }

        // 点击背景关闭全屏
        document.getElementById('fullscreenModal').addEventListener('click', function (e) {
            if (e.target === this) {
                closeFullscreen();
            }
        });

        // 重置抽奖
        function resetLottery() {
            document.getElementById('prizeInput').value = '';
            document.getElementById('cardsContainer').innerHTML = '';
            closeFullscreen();
            showInputSection();
            hideRestartButton();
        }

        // 页面加载完成后的初始化
        document.addEventListener('DOMContentLoaded', function () {
            // 添加默认奖品示例
            document.getElementById('prizeInput').value = '精品铅笔📝：书写美好未来\n精美贴画🎨：装饰你的梦想\n美味零食🍪：补充能量时刻\n神秘大礼包🎁：超值惊喜等着你\n幸运安慰奖✨：下次一定更好';
        });

        // ESC键关闭全屏
        document.addEventListener('keydown', function (e) {
            if (e.key === 'Escape') {
                closeFullscreen();
            }
        });
    </script>
</body>

</html>